﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CompanyBussiness
{
    public class LanguagesManagement
    {
        private CompanyDataContext companydata = new CompanyDataContext();

        public virtual Language GetLanguageByID(int languagesID)
        {
            var language=(from la in companydata.Languages
                          where la.LanguagesID==languagesID
                          select la).Single();
            return language;
        }

        public virtual Language GetLanguageByCode(string countryCode)
        {
            var language = (from la in companydata.Languages
                            where la.countryCode == countryCode
                            select la).Single();
            return language;
        }

        public virtual List<Language> GetLanguageList(Boolean languageStatus)
        { 
            var language=(from la in companydata.Languages
                          where la.LanguageStatus==languageStatus
                          select la).ToList();
            return language;
        }

        public virtual IQueryable GetLanguage(Boolean languageStatus)
        {
            var language = (from la in companydata.Languages
                            where la.LanguageStatus == languageStatus
                            select la);
            return language;
        }

        public virtual void CreateLanguage(string countryName, string countryCode, string countryDescription, string countryImg, Boolean languageStatus)
        {
            Language language = new Language();
            language.countryName = countryName;
            language.countryCode = countryCode;
            language.countryDescription = countryDescription;
            language.countryImg = countryImg;
            language.LanguageStatus = languageStatus;

            companydata.Languages.InsertOnSubmit(language);
            companydata.SubmitChanges();
        }
        public virtual void UpdateLanguage(int languagesID, string countryName, string countryCode, string countryDescription, string countryImg, Boolean languageStatus)
        {
            var language = (from la in companydata.Languages
                            where la.LanguagesID == languagesID
                            select la).Single();
            language.countryName = countryName;
            language.countryCode = countryCode;
            language.countryDescription = countryDescription;
            language.countryImg = countryImg;
            language.LanguageStatus = languageStatus;

            companydata.SubmitChanges();

        }
        public virtual void DeleteLanguage(int languagesID)
        {
            var language = (from la in companydata.Languages
                            where la.LanguagesID == languagesID
                            select la).Single();

            companydata.Languages.DeleteOnSubmit(language);
            companydata.SubmitChanges();
        }

        public virtual TagTranslation GetTagByLanguageIDandTagName(string tagName, int languageID)
        {
            var Tag = (from p in companydata.TagTranslations
                       where p.TagName == tagName && p.LanguagesID == languageID
                       select p).FirstOrDefault();

            return Tag;
        }
        public virtual string GetTagValueByLanguageIDandTagName(string tagName, int languageID)
        {
            var Tag = (from p in companydata.TagTranslations
                       where p.TagName == tagName && p.LanguagesID == languageID
                       select p).FirstOrDefault();

            return Tag != null ? Tag.TagValue : "";
        }
    }
}
